package com.chenille.tools.util

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ListView
import java.io.*
import java.math.BigDecimal
import java.math.RoundingMode
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
import java.util.regex.Matcher
import java.util.regex.Pattern
import java.util.regex.PatternSyntaxException

/**
 * @Author: FALLS CHEN
 * @Date: 2020-01-09 17:28
 * EMAIL: 636e68747474403136332e636f6d
 * @Version 1.0
 */

object GeneralUtils {

    /**
     * <获取当前日期 格式 yyyyMMddHHmmss> <功能详细描述>
     *
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></获取当前日期> */
    val rightNowDateString: String
        get() {
            val calendar = Calendar.getInstance(Locale.CHINA)
            val date = calendar.time
            val dateFormat = SimpleDateFormat("yyyyMMddHHmmss")
            return dateFormat.format(date)
        }

    /**
     * <获取当前时间 格式yyyyMMddHHmmss> <功能详细描述>
     *
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></获取当前时间> */
    val rightNowDateTime: Date?
        get() {
            val calendar = Calendar.getInstance(Locale.CHINA)
            val date = calendar.time
            val dateFormat = SimpleDateFormat("yyyyMMddHHmmss")
            try {
                return dateFormat.parse(dateFormat.format(date))
            } catch (e: ParseException) {
                e.printStackTrace()
                return null
            }

        }

    /**
     * 获取设备型号
     *
     * @return
     */
    val deviceModel: String
        get() = android.os.Build.MODEL


    private var inflater: LayoutInflater? = null

    /**
     * 判断对象是否为null , 为null返回true,否则返回false
     *
     * @param obj 被判断的对象
     * @return boolean
     */
    fun isNull(obj: Any?): Boolean {
        return if (null == obj) true else false
    }
    fun isVideo(obj: String?): Boolean {
        var fi= false
        obj?.let {
            fi = MediaFile.isVideoFileType(it)
            if (!fi)fi=(it.contains(".mp4"))
        }
        return fi
    }

    /**
     * 判断对象是否为null , 为null返回false,否则返回true
     *
     * @param obj 被判断的对象
     * @return boolean
     */
    fun isNotNull(obj: Any): Boolean {
        return !isNull(obj)
    }

    /**
     * 判断字符串是否为null或者0长度，字符串在判断长度时，先去除前后的空格,空或者0长度返回true,否则返回false
     *
     * @param str 被判断的字符串
     * @return boolean
     */
    fun isNullOrZeroLenght(str: String?): Boolean {
        str?.let {
            KLog.e(it)
        }
        return null == str || "" == str.trim { it <= ' ' }|| str.isEmpty()||str=="null"
    }

    /**
     * 判断字符串是否为null或者0长度，字符串在判断长度时，先去除前后的空格,空或者0长度返回false,否则返回true
     *
     * @param str 被判断的字符串
     * @return boolean
     */
    fun isNotNullOrZeroLenght(str: String?): Boolean {
        return !isNullOrZeroLenght(str)
    }

    /**
     * 判断集合对象是否为null或者0大小 , 为空或0大小返回true ,否则返回false
     *
     * @param c collection 集合接口
     * @return boolean 布尔值
     * @see [类、类.方法、类.成员]
     */
    fun isNullOrZeroSize(c: Collection<Any>): Boolean {
        return isNull(c) || c.isEmpty()
    }

    /**
     * 判断集合对象是否为null或者0大小 , 为空或0大小返回false, 否则返回true
     *
     * @param c collection 集合接口
     * @return boolean 布尔值
     * @see [类、类.方法、类.成员]
     */
    fun isNotNullOrZeroSize(c: Collection<Any>?): Boolean {
        if (c==null) return false
        return !isNullOrZeroSize(c)
    }

    /**
     * 判断数字类型是否为null或者0，如果是返回true，否则返回false
     *
     * @param number 被判断的数字
     * @return boolean
     */
    fun isNullOrZero(number: Number): Boolean {
        return if (isNotNull(number)) {
            if (number.toInt() != 0) false else true
        } else true
    }

    /**
     * 判断数字类型是否不为null或者0，如果是返回true，否则返回false
     *
     * @param number 被判断的数字
     * @return boolean
     */
    fun isNotNullOrZero(number: Number): Boolean {
        return !isNullOrZero(number)
    }


    /**
     * 判断字符串是否为URL
     *
     * @param urls 需要判断的String类型url
     * @return true:是URL；false:不是URL
     */
    fun isHttpUrl(urls: String): Boolean {
        var isurl = false
        val regex =
            "(((https|http)?://)?([a-z0-9]+[.])|(www.))" + "\\w+[.|\\/]([a-z0-9]{0,})?[[.]([a-z0-9]{0,})]+((/[\\S&&[^,;\u4E00-\u9FA5]]+)+)?([.][a-z0-9]{0,}+|/?)"//设置正则表达式
        val pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE)
        val mat = pat.matcher(urls.trim { it <= ' ' })
        isurl = mat.matches()//判断是否匹配
        if (isurl) {
            isurl = true
        }
        return isurl
    }


    /**
     * <保留两位有效数字> <功能详细描述>
     *
     * @param num String
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></保留两位有效数字> */
    fun retained2SignificantFigures(num: String): String {
        return BigDecimal(num).setScale(2, RoundingMode.HALF_UP).toString()
    }

    /**
     * <减法运算并保留两位有效数字> <功能详细描述>
     *
     * @param subt1 String
     * @param subt2 String
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></减法运算并保留两位有效数字> */
    fun subtract(subt1: String, subt2: String): String {
        val sub1 = BigDecimal(subt1)
        val sub2 = BigDecimal(subt2)
        var result = sub1.subtract(sub2)
        result = result.setScale(2, RoundingMode.HALF_UP)
        return result.toString()
    }

    /**
     * <加法运算并保留两位有效数字> <功能详细描述>
     *
     * @param addend1
     * @param addend2
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></加法运算并保留两位有效数字> */
    fun add(addend1: String, addend2: String): String {
        val add1 = BigDecimal(addend1)
        val add2 = BigDecimal(addend2)
        var result = add1.add(add2)
        result = result.setScale(2, RoundingMode.HALF_UP)
        return result.toString()
    }

    /**
     * <乘法运算并保留两位有效数字> <功能详细描述>
     *
     * @param factor1 String
     * @param factor2 String
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></乘法运算并保留两位有效数字> */
    fun multiply(factor1: String, factor2: String): String {
        val fac1 = BigDecimal(factor1)
        val fac2 = BigDecimal(factor2)
        var result = fac1.multiply(fac2)
        result = result.setScale(2, RoundingMode.HALF_UP)
        return result.toString()
    }

    /**
     * <除法运算并保留两位有效数字> <功能详细描述>
     *
     * @param divisor1 String
     * @param divisor2 String
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></除法运算并保留两位有效数字> */
    fun divide(divisor1: String, divisor2: String): String {
        val div1 = BigDecimal(divisor1)
        val div2 = BigDecimal(divisor2)
        val result = div1.divide(div2, 2, RoundingMode.HALF_UP)
        return result.toString()
    }

    /**
     * <除法运算并保留两位有效数字> <功能详细描述>
     *
     * @param divisor1 String
     * @param divisor2 String
     * @return String
     * @see [类、类.方法、类.成员]
    </功能详细描述></除法运算并保留两位有效数字> */
    fun dividePoint1(divisor1: String, divisor2: String): String {
        val div1 = BigDecimal(divisor1)
        val div2 = BigDecimal(divisor2)
        val result = div1.divide(div2, 1, RoundingMode.HALF_UP)
        return result.toString()
    }

    /**
     * <将YYYYMMDDHHmmss 转换为 YYYY-MM-DD> <功能详细描述>
     *
     * @param str
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></将YYYYMMDDHHmmss> */
    fun splitTodate(str: String): String? {
        if (isNullOrZeroLenght(str) || str.length != 14) {
            return str
        }

        var strs = ""
        strs = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, 8)
        return strs
    }

    /**
     * <将YYYYMMDDHHmmss 转换为 YYYY-MM-DD hh:mm> <功能详细描述>
     *
     * @param str
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></将YYYYMMDDHHmmss> */
    fun splitToMinute(str: String): String? {
        if (isNullOrZeroLenght(str) || str.length != 14) {
            return str
        }

        var strs = ""
        strs = (str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(
            6,
            8
        ) + " " + str.substring(8, 10)
                + ":" + str.substring(10, 12))
        return strs
    }

    /**
     * <将YYYY-MM-DD 转换为 YYYYMMDD> <功能详细描述>
     *
     * @param str
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></将YYYY-MM-DD> */
    fun splitToMinuteNoLine(str: String): String {
        if (!str.contains("-")) {
            return str
        }
        var strs = ""
        val strsArr = str.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        if (strsArr[1].length == 1) {
            strsArr[1] = "0" + strsArr[1]
        }

        if (strsArr[2].length == 1) {
            strsArr[2] = "0" + strsArr[2]
        }

        strs = strsArr[0] + strsArr[1] + strsArr[2]
        return strs
    }

    /**
     * <将YYYYMMDDHHmmss 转换为 YYYY-MM-DD hh:mm:ss> <功能详细描述>
     *
     * @param str
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></将YYYYMMDDHHmmss> */
    fun splitToSecond(str: String): String? {
        if (isNullOrZeroLenght(str) || str.length != 14) {
            return str
        }

        var strs = ""
        strs = (str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(
            6,
            8
        ) + " " + str.substring(8, 10)
                + ":" + str.substring(10, 12) + ":" + str.substring(12, 14))
        return strs
    }

    /**
     * <将YYYYMMDDHHmmss 转换为 YY-MM-DD hh:mm:ss> <功能详细描述>
     *
     * @param str
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></将YYYYMMDDHHmmss> */
    fun splitToYear(str: String): String? {
        if (isNullOrZeroLenght(str) || str.length != 14) {
            return str
        }

        var strs = ""
        strs = (str.substring(2, 4) + "-" + str.substring(4, 6) + "-" + str.substring(
            6,
            8
        ) + " " + str.substring(8, 10)
                + ":" + str.substring(10, 12) + ":" + str.substring(12, 14))
        return strs
    }

    /**
     * <邮箱判断>
     * <功能详细描述>
     *
     * @param email
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></邮箱判断> */
    fun isEmail(email: String): Boolean {
        val str =
            "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"
        val p = Pattern.compile(str)
        val m = p.matcher(email)
        return m.matches()
    }

    /**
     * <手机号码判断>
     *
     * @param tel
     * @return
     * @see [类、类.方法、类.成员]
    </手机号码判断> */
    fun isTel(tel: String): Boolean {
        val str = "^((17[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"
        val p = Pattern.compile(str)
        val m = p.matcher(tel)
        return m.matches()
    }

    /**
     * 大陆号码或香港号码均可
     */
    @Throws(PatternSyntaxException::class)
    fun isPhoneLegal(str: String): Boolean {
        return isChinaPhoneLegal(str) || isHKPhoneLegal(str)
    }

    fun formatDateDM(dateStr: String): String {
        try {
            val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
            val date = formatter.parse(dateStr)
            val sdf = SimpleDateFormat("MM/dd")
            return sdf.format(date)
        } catch (e: Exception) {
            return dateStr
        }

    }

    /**
     * 大陆手机号码11位数，匹配格式：前三位固定格式+后8位任意数
     * 此方法中前三位格式有：
     * 13+任意数
     * 15+除4的任意数
     * 18+除1和4的任意数
     * 17+除9的任意数
     * 147
     */
    @Throws(PatternSyntaxException::class)
    fun isChinaPhoneLegal(str: String): Boolean {
        // ^ 匹配输入字符串开始的位置
        // \d 匹配一个或多个数字，其中 \ 要转义，所以是 \\d
        // $ 匹配输入字符串结尾的位置
        val regExp1 =
            "(^((0[1,2]{1}\\\\d{1}-?\\\\d{8})|(0[3-9]{1}\\\\d{2}-?\\\\d{7,8}))$)|(^(0|86|17951)?(13[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[89]|14[57])[0-9]{8}$)"
        val p = Pattern.compile(regExp1)
        val m = p.matcher(str)
        return m.matches()
    }

    /**
     * 香港手机号码8位数，5|6|8|9开头+7位任意数
     */
    @Throws(PatternSyntaxException::class)
    fun isHKPhoneLegal(str: String): Boolean {
        // ^ 匹配输入字符串开始的位置
        // \d 匹配一个或多个数字，其中 \ 要转义，所以是 \\d
        // $ 匹配输入字符串结尾的位置
        val regExp = "^(5|6|8|9)\\d{7}$"
        val p = Pattern.compile(regExp)
        val m = p.matcher(str)
        return m.matches()

    }

    /**
     * <邮编判断>
     * <功能详细描述>
     *
     * @param post
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></邮编判断> */
    fun isPost(post: String): Boolean {
        val patrn = "^[1-9][0-9]{5}$"
        val p = Pattern.compile(patrn)
        val m = p.matcher(post)
        return m.matches()
    }

    /**
     * <密码规则判断>
     * <功能详细描述>
     *
     * @param password
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></密码规则判断> */
    fun IsPassword(password: String): Boolean {
        val str = "^[A-Za-z0-9_]{6,20}$"
        val p = Pattern.compile(str)
        val m = p.matcher(password)
        return m.matches()
    }

    /**
     * <密码位数判断>
     * <功能详细描述>
     *
     * @param password
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></密码位数判断> */
    fun IsPasswordDigit(password: String): Boolean {
        val str = "^[^ ]{6,20}$"
        val p = Pattern.compile(str)
        val m = p.matcher(password)
        return m.matches()
    }

    /**
     * <密码位数判断>
     * <功能详细描述>
     *
     * @param certificate
     * @return
     * @see [类、类.方法、类.成员]
    </功能详细描述></密码位数判断> */
    fun Iscertificate(certificate: String): Boolean {
        val str = "[0-9]{17}([0-9]|[xX])"
        val p = Pattern.compile(str)
        val m = p.matcher(certificate)
        return m.matches()
    }

    /**
     * @param listView
     */
    fun setListViewHeightBasedOnChildrenExtend(listView: ListView) {
        val listAdapter = listView.adapter ?: return
        val desiredWidth =
            View.MeasureSpec.makeMeasureSpec(listView.width, View.MeasureSpec.AT_MOST)
        var totalHeight = 0
        var view: View? = null
        for (i in 0 until listAdapter.count) {
            view = listAdapter.getView(i, view, listView)
            if (i == 0) {
                view!!.layoutParams =
                    ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)
            }
            view!!.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED)
            totalHeight += view.measuredHeight
        }
        val params = listView.layoutParams
        params.height = totalHeight + listView.dividerHeight * (listAdapter.count - 1)
        listView.layoutParams = params
        listView.requestLayout()
    }

    // 去除textview的排版问题
    fun ToDBC(input: String): String {
        val c = input.toCharArray()
        for (i in c.indices) {
            if (c[i].toInt() == 12288) {
                c[i] = 32.toChar()
                continue
            }
            if (c[i].toInt() in 65281..65374)
                c[i] = (c[i].toInt() - 65248).toChar()
        }
        return String(c)
    }


    /**
     * 获取版本信息
     *
     * @return
     * @throws Exception
     */
    fun getVersionName(context: Context): String {
        try {
            val packageManager = context.packageManager
            val packInfo = packageManager.getPackageInfo(context.packageName, 0)
            return packInfo.versionName
        } catch (e: PackageManager.NameNotFoundException) {
        }

        return ""
    }


    fun formatDateT(dateStr: String): String {
        try {
            val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
            val date = formatter.parse(dateStr)
            val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm")
            return sdf.format(date)
        } catch (e: Exception) {
            return dateStr
        }

    }

    /*
     * @Author couldxtra
     * @Description  是否需要显示邮箱
     * @Date 10:06 AM 2019/2/20
     * @Param [email]
     * @return java.lang.String
     * @Version 1
     **/
    fun visibleText(string: String): String {
        if (isNotNullOrZeroLenght(string)) {
            var startStr = ""
            var endStr = ""
            if (string.length > 5) {
                startStr = string.substring(0, 2)
                endStr = string.substring(string.length - 2, string.length)

                return "$startStr****$endStr"

            } else
                return string.substring(0, 1) + "*****"
        } else
            return ""
    }

    //根据图片地址转换为base64编码字符串
    fun toBase64(imgFile: String): String {
        var inputStream: InputStream? = null
        var data: ByteArray? = null
        try {
            inputStream = FileInputStream(imgFile)
            data = ByteArray(inputStream.available())
            inputStream.read(data)
            inputStream.close()
        } catch (e: IOException) {
            e.printStackTrace()
        }

        // 加密
        return android.util.Base64.encodeToString(data, android.util.Base64.DEFAULT)
    }

    fun toBase64(file: File?): String? {
        if (file == null) {
            return null
        }
        var base64: String? = null
        var fin: FileInputStream? = null
        try {
            fin = FileInputStream(file)
            val buff = ByteArray(fin.available())
            fin.read(buff)
            base64 = android.util.Base64.encodeToString(buff, android.util.Base64.DEFAULT)
        } catch (e: FileNotFoundException) {
            e.printStackTrace()
        } catch (e: IOException) {
            e.printStackTrace()
        } finally {
            if (fin != null) {
                try {
                    fin.close()
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }
        }
        return base64
    }

    fun inflate(context: Context, res: Int): View {
        if (inflater == null) {
            inflater = LayoutInflater.from(context)
        }
        return inflater!!.inflate(res, null)
    }

    fun formatDateZ(dateStr: String): String {
        try {
            val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
            formatter.timeZone = TimeZone.getTimeZone("UTC")
            val date = formatter.parse(dateStr)
            val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm")
            return sdf.format(date)
        } catch (e: Exception) {
            return dateStr
        }

    }

    /**
     * 启动到应用商店app详情界面
     *
     * @param appPkg    目标App的包名
     * @param marketPkg 应用商店包名 ,如果为""则由系统弹出应用商店列表供用户选择,否则调转到目标市场的应用详情界面，某些应用商店可能会失败
     */
    fun launchAppDetail(context: Context, appPkg: String, marketPkg: String) {
        try {
            if (TextUtils.isEmpty(appPkg)) return

            val uri = Uri.parse("market://details?id=$appPkg")
            val intent = Intent(Intent.ACTION_VIEW, uri)
            if (!TextUtils.isEmpty(marketPkg)) {
                intent.setPackage(marketPkg)
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }


    /**
     * 得到当前应用版本名称的方法
     *
     * @param context
     * :上下文
     * @throws Exception
     */
    @Throws(Exception::class)
    fun getVersion(context: Context): Int {
        // 获取packagemanager的实例
        val packageManager = context.packageManager
        // getPackageName()是你当前类的包名
        val packInfo = packageManager.getPackageInfo(context.packageName, 0)
        return packInfo.versionCode
    }

    fun secToTime(seconds: Long): String {
        val hour = seconds / 3600
        val minute = (seconds - hour * 3600) / 60
        val second = seconds - hour * 3600 - minute * 60

        val sb = StringBuffer()
        if (hour > 0) {
            sb.append("$hour:")
        }

        if (minute > 0) {
            sb.append("$minute:")
        }
        if (second > 0) {
            sb.append(second.toString())
        }
        if (second.toInt() == 0) {
            sb.append("00")
        }
        return sb.toString()
    }


    /**
     * 将int类型数字转换成时分秒毫秒的格式数据
     *
     * @param time long类型的数据
     * @return HH:mm:ss.SSS
     * @author zero 2019/04/11
     */
    fun msecToTime(time: Int): String {
        var timeStr: String? = null
        var hour = 0
        var minute = 0
        var second = 0
        var millisecond = 0
        if (time <= 0)
            return "00:00:00.000"
        else {
            second = time / 1000
            minute = second / 60
            millisecond = time % 1000
            if (second < 60) {
                timeStr = "00:00:" + unitFormat(second) + "." + unitFormat2(millisecond)
            } else if (minute < 60) {
                second = second % 60
                timeStr = "00:" + unitFormat(minute) + ":" + unitFormat(second) + "." + unitFormat2(
                    millisecond
                )
            } else {// 数字>=3600 000的时候
                hour = minute / 60
                minute = minute % 60
                second = second - hour * 3600 - minute * 60
                timeStr =
                    (unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second) + "."
                            + unitFormat2(millisecond))
            }
        }
        return timeStr
    }

    fun unitFormat(i: Int): String {// 时分秒的格式转换
        var retStr: String? = null
        if (i >= 0 && i < 10)
            retStr = "0" + Integer.toString(i)
        else
            retStr = "" + i
        return retStr
    }

    fun unitFormat2(i: Int): String {// 毫秒的格式转换
        var retStr: String? = null
        if (i >= 0 && i < 10)
            retStr = "00" + Integer.toString(i)
        else if (i >= 10 && i < 100) {
            retStr = "0" + Integer.toString(i)
        } else
            retStr = "" + i
        return retStr
    }

    fun formatDateTime(seconds: Long): String {
        val day = seconds / (60 * 60 * 24)//换成天
        val hour = (seconds - 60 * 60 * 24 * day) / 3600//总秒数-换算成天的秒数=剩余的秒数    剩余的秒数换算为小时
        val minute =
            (seconds - 60 * 60 * 24 * day - 3600 * hour) / 60//总秒数-换算成天的秒数-换算成小时的秒数=剩余的秒数    剩余的秒数换算为分
        val second =
            seconds - 60 * 60 * 24 * day - 3600 * hour - 60 * minute//总秒数-换算成天的秒数-换算成小时的秒数-换算为分的秒数=剩余的秒数

        return day.toString() + "天" + formatNum(hour) + "时" + formatNum(minute) + "分" + formatNum(
            second
        ) + "秒"

    }

    private fun formatNum(number: Long): String {

        return if (number > 9)
            number.toString()
        else "0$number"

    }


    /** 是否是汉字的正则 */
    public fun matchRegular(name: String): Boolean {
        val pattern = Pattern.compile("[\\u4e00-\\u9fa5]+")
        val matcher: Matcher = pattern.matcher(name)
        return matcher.matches()

    }


}











